package io.renren.modules.device.service.impl;

import io.renren.common.utils.Constant;
import io.renren.modules.sys.shiro.ShiroUtils;
import org.springframework.stereotype.Service;
import java.util.Map;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;

import io.renren.modules.device.dao.DeviceDao;
import io.renren.modules.device.entity.DeviceEntity;
import io.renren.modules.device.service.DeviceService;


@Service("deviceService")
public class DeviceServiceImpl extends ServiceImpl<DeviceDao, DeviceEntity> implements DeviceService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        EntityWrapper<DeviceEntity> query = new EntityWrapper<DeviceEntity>();
        if(!ShiroUtils.getUserId().equals(Constant.SUPER_ADMIN)){
            query.and(" building_code in (select building_code from tb_building where  dept_id in  (select  d.dept_id from    sys_dept d inner join sys_user u  on d.dept_id=u.dept_id" +
                    " where   u.user_id={0} and ( d.parent_id=u.dept_id or d.dept_id=u.dept_id )))",ShiroUtils.getUserId());
        }

        Page<DeviceEntity> page = this.selectPage(
                new Query<DeviceEntity>(params).getPage(),
              query
        );

        return new PageUtils(page);
    }

}
